<!DOCTYPE html>
<html lang="zh-CN"  xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>课程过程化管理 </title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/bootstrap/css/bootstrap.min.css}">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" th:href="@{/static/vendor/font-awesome/css/font-awesome.min.css}">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" th:href="@{/static/css/fontastic.css}">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" th:href="@{https://fonts.googleapis.com/css?family=Poppins:300,400,700}">
    <!-- theme stylesheet-->
    <link rel="stylesheet" th:href="@{/static/css/style.default.css}" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" th:href="@{/static/css/custom.css}">
    <!-- Favicon-->
    <link rel="shortcut icon" th:href="@{/static/img/favicon.ico}">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->


  </head>
  <body>
    <div class="page">
      <!-- Main Navbar-->
      <header class="header">
        <nav class="navbar">
          <!-- Search Box-->
          <div class="search-box">
            <button class="dismiss"><i class="icon-close"></i></button>
            <form id="searchForm" action="#" role="search">
              <input type="search"  id="myInput" onkeyup="myFunction();" placeholder="What are you looking for...(通过id搜索)" class="form-control">
            </form>
          </div>
          <div class="container-fluid">
            <div class="navbar-holder d-flex align-items-center justify-content-between">
              <!-- Navbar Header-->
              <div class="navbar-header">
                <!-- Navbar Brand --><a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                  <div class="brand-text d-none d-lg-inline-block"><strong>侧栏</strong></div>
                  <div class="brand-text d-none d-sm-inline-block d-lg-none"><strong>BD</strong></div></a>
                <!-- Toggle Button--><a id="toggle-btn" href="#" class="menu-btn active"><span></span><span></span><span></span></a>
              </div>
              <!-- Navbar Menu -->
              <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                <!-- Search-->
                <li class="nav-item d-flex align-items-center"><a id="search" href="#"><i class="icon-search"></i></a></li>
                <!-- Notifications-->
                <li class="nav-item dropdown"> <a id="notifications" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell-o"></i><span class="badge bg-red badge-corner">1</span></a>
                  <ul aria-labelledby="notifications" class="dropdown-menu">
                    <li><a rel="nofollow" href="#" class="dropdown-item"> 
                        <div class="notification">

                        </div></a></li>
                    <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong>view all notifications                                            </strong></a></li>
                  </ul>
                </li>
                <!-- Logout    -->
                <li class="nav-item"><a th:href="@{/logout}" class="nav-link logout"> <span class="d-none d-sm-inline">退出登录</span><i class="fa fa-sign-out"></i></a></li>
              </ul>
            </div>
          </div>
        </nav>
      </header>
      <div class="page-content d-flex align-items-stretch"> 
        <!-- Side Navbar -->
        <nav class="side-navbar">
          <!-- Sidebar Header-->
          <div class="sidebar-header d-flex align-items-center">
            <div class="avatar"><img th:src="@{/static/img/avatar-1.jpg}" alt="..." class="img-fluid rounded-circle"></div>
            <div class="title">
              <h1 class="h4" th:text="${session.Main.getTname()}"></h1>
              <p>老师编号：[[${session.loginUser}]]</p></p>
            </div>
          </div>
          <!-- Sidebar Navidation Menus--><span class="heading">Main</span>
          <ul class="list-unstyled">
                    <li class="active"><a th:href="@{/teachers/course_students/{cid}(cid=${cid})}"> </i>学生管理 </a></li>
                    <li><a th:href="@{/teacherMain}"> <i class="icon-interface-windows"></i>返回教师主页 </a></li>
          </ul>
        </nav>
        <div class="content-inner">
          <!-- Page Header-->
          <header class="page-header">
            <div class="container-fluid">
              <a class="no-margin-bottom" th:href="@{/teacherMain}">返回</a>
            </div>
          </header>

          <br>

          <div >
            <table id="table" class="table table-hover table-bordered" border="1"align="center">
              <thead  class="font"><th>学号</th><th>学生姓名</th><th>学生班级</th><th>性别</th><th>平均成绩</th><th>操作</th></thead>
              <tbody>
              <tr th:each="a,aState:${cs}">
                  <td th:text="${a.getStudent().getId()}"></td>
                  <td th:text="${a.getStudent().getSname()}"></td>
                  <td th:text="${a.getStudent().getClassName().getClassname()}"></td>
                  <!-- 判断男女 -->
                  <td th:if="${a.getStudent().getSsex()==1}">男</td>
                  <td th:if="${a.getStudent().getSsex()==0}">女</td>

                  <td th:if="${avState.index}==${size}*(${page.pageNum}-1)+${aState.index}" th:each="av,avState:${averSores}"
                      th:text="${av}">
                  </td>

                <td>
                  <a th:if="${a.getIfjoin()}==2" th:href="@{/teachers/deleteStu/{id}/{cid}/{pageNum}(id=${a.getStudent().getId()},cid=${a.getCourse().getCid()},pageNum=${page.pageNum})}"
                     class="btn btn-danger">申请删除</a>
                  <a th:if="${a.getIfjoin()}==3" th:href="@{/teachers/cancelDelStu/{id}/{cid}/{pageNum}
                    (cid=${a.getCourse().getCid()},id=${a.getStudent().getId()},pageNum=${page.pageNum})}" class="btn btn-info">撤销删除</a>

                  <!--<a class="btn btn-info" th:href="@{/teachers/StuScores/{id}/{cid}(id=${a.getStudent().getId()},cid=${a.getCourse().getCid()})}">成绩管理</a>-->
                  <button id="StuBtn" class="btn btn-info" data-toggle="modal" data-target="#editModal" th:onclick="editInfo([[${aState.index}]],[[${a.getStudent().getId()}]],[[${size}]])">成绩管理</button>

                </td>
              </tr>
              </tbody>
            </table>
            <div style="text-align: center">
              <a href="?start=1" style="display: inline-block;">[首  页]</a>  <!-- 这是相对路径的写法。 前面没有斜线就是相对当前路径加上这个地址。 -->
              <div th:if="${page.pageNum - 1 > 0}" style="display: inline-block;">
                <a th:href="@{'?start='+${page.pageNum - 1}}" >[上一页]</a>
              </div>
              <div th:if="${page.pageNum +1 < page.pages +1}" style="display: inline-block;">
                <a th:href="@{'?start='+${page.pageNum + 1}}" >[下一页]</a>
              </div>
              <a th:href="@{'?start='+${page.pages}}" style="display: inline-block;">[末  页]</a>
            </div>
            <div align="center">
              当前页/总页数：<a th:href="@{'?start='+${page.pageNum}}" th:text="${page.pageNum}"></a>/<a th:href="@{'?start='+${page.pages}}" th:text="${page.pages}"></a>
            </div>
          </div>

          <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="myModalLabel">
                    成绩（点击修改）
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                  <div class="modal-body">
                    <table class="table table-hover table-bordered" border="1"align="center">

                      <thead>
                        <tr><th>章节</th><th>成绩</th></tr>
                      </thead>

                      <tbody id="StuSocres">
                      </tbody>

                    </table>

                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" class="btn btn-primary" id="editScores">
                      更新
                    </button>
                  </div>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>




          <div class="modal fade" id="qiandaoModal" tabindex="-1" role="dialog" aria-labelledby="qiandaoModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">

                <div class="modal-header">
                  <h4 class="modal-title" id="qiandaoModalLabel">
                    签到情况（点击修改）
                  </h4>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×
                  </button>
                </div>
                <div class="modal-body">
                  <table class="table table-hover table-bordered" border="1"align="center">

                    <thead>
                    <tr><th>签到序列</th><th>签到情况</th></tr>
                    </thead>

                    <tbody id="StuQiandao">
                    </tbody>

                  </table>

                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                  </button>
                  <button type="button" class="btn btn-primary" id="editQiandao">
                    更新
                  </button>
                </div>

              </div>

              <!-- /.modal-content -->

            </div>

            <!-- /.modal -->
          </div>



          <script language='javascript' th:inline="javascript">
            window.onload=function () {
                for (var i=1;i<[[${size}]]+1;i++){
                    var score=document.getElementById("table").rows[i].cells[4].innerHTML;
                    var s=Number(score);
                    if(s<60){
                        document.getElementById("table").rows[i].cells[4].style.cssText="color:red;";
                    }else if(s>=60 && s<=65){
                        document.getElementById("table").rows[i].cells[4].style.cssText="color:#ffd811;";
                    }else if(s>90){
                        document.getElementById("table").rows[i].cells[4].style.cssText="color:#39c764;";
                    }
                }

            }


              // 展示学生成绩
              function editInfo(id,StuId,size) {
                  var num=size*([[${page.pageNum}]]-1)+id;
                  var scores=[[${scores}]][num];
                  //动态创建表格的方式，使用拼接html的方式 （推荐）
                  var html = "";
                  for( var i = 0; i < scores.length; i++ ) {
                       html += "<tr>";
                       html +=     "<td>" + [[${chapters}]][i] + "</td>"
                      if (Number(scores[i])>90){
                          html +=     "<td id='ssr"+i+"' style='color: #39c764'>" + scores[i] + "</td>"
                      } else if(Number(scores[i])<60){
                          html +=     "<td id='ssr"+i+"' style='color: red'>" + scores[i] + "</td>"
                      }else {
                          html +=     "<td id='ssr"+i+"'>" + scores[i] + "</td>"
                      }
                       html += "</tr>";
                  }
                  //生成新表格
                  $("#StuSocres").html(html);

                  $('#StuSocres td').click(function(){
                      if(!$(this).is('.input')){
                          $(this).addClass('input').html('<input type="text" style="width: 66px" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){//当点击后会给他一个
                              //var thisid = $(this).parent().siblings("th:eq(0)").text();//返回同行的0列元素，即id
                              var thisvalue=$(this).val();//获得值
                              //var thisclass = $(this).parent().attr("class");
                              $(this).parent().removeClass('input').html($(this).val() || 0);
                          });
                      }
                  })/*.hover(function(){
                      $(this).addClass('hover');
                  },function(){
                      $(this).removeClass('hover');
                  })*/;

                  $('#editScores').unbind("click").bind("click",function(){//bind("click",function()相当于click(function()
                      //$("#editScores").click(function(){ //必须加unbind("click")清除之前的点击事件
                      var sum=[];
                      for (var i=0;i<scores.length;i++){
                          sum[i]=document.getElementById("ssr"+i).innerText;;
                      }
                      var result=sum.join("||");
                      /*<![CDATA[*/
                      var addUrl = /*[[@{/teachers/AddScores}]]*/;//获取动作地址
                      /*]]>*/
                      $.ajax({
                          type: "POST",
                          url: addUrl,
                          async:true,
                          dataType:'json',
                          data: {
                              "scores": result,
                              "cid": [[${cid}]],
                              "id": StuId
                          },
                          success: function(data) {
                              //$('#editScores').off('click');
                              //$('#StuBtn').off('click');
                              $('#editModal').modal('hide');
                              alert(data.msg);
                              parent.location.reload();
                          }
                      });
                  });
              }
          </script>



          <style type="text/css">
            tr.font {
              font-size: 20px;
            }
            table.imagetable {
              font-family: verdana,arial,sans-serif;
              font-size:11px;
              color:#333333;
              border-width: 1px;
              border-color: #999999;
              border-collapse: collapse;
            }
            table.imagetable th {
              background:#b5cfd2 url('css/bulecell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }
            table.imagetable td {
              background:#dcddc0 url('css/greycell.jpg');
              border-width: 1px;
              padding: 8px;
              border-style: solid;
              border-color: #999999;
            }
          </style>

          <!-- Page Footer-->
          <footer class="main-footer">
            <div class="container-fluid">
              <div class="row">
                <div class="col-sm-6">
                  <p>成都信息工程大学 &copy; 2019</p>
                </div>
              </div>
            </div>
          </footer>
        </div>
      </div>
    </div>
    <!-- JavaScript files-->
    <script th:src="@{/static/vendor/jquery/jquery.min.js}"></script>
    <script th:src="@{/static/vendor/popper.js/umd/popper.min.js}"> </script>
    <script th:src="@{/static/vendor/bootstrap/js/bootstrap.min.js}"></script>
    <script th:src="@{/static/vendor/jquery.cookie/jquery.cookie.js}"> </script>
    <script th:src="@{/static/vendor/chart.js/Chart.min.js}"></script>
    <script th:src="@{/static/vendor/jquery-validation/jquery.validate.min.js}"></script>
    <script th:src="@{/static/js/charts-home.js}"></script>
    <script th:src="@{/static/js/findFunction.js}"></script><!--搜索功能-->
    <!-- Main File-->
    <script th:src="@{/static/js/front.js}"></script>
  </body>
</html>